<header>
    <div class="a-bar">
        <a href="javascript:history.back()" class="a-back">
		    <i class="arr left"></i>
            <{t}>返回<{/t}>
        </a>
        <span class="a-name"><{t}>商品管理<{/t}></span>
		<div class="a-right">
        </div>
    </div>
</header>
<div class="full-padding">
    <div class="pro-search">
		<form action="<{link app=b2c ctl=wap_member act=manager_goods}>" method="post" class="member-checkform">
			<div class="data-so">
				 <label><{t}>品牌：<{/t}></label>
				 <{input type='select' id="sel_brand" name="content[brand_id]" options=$brands value=$content.brand_id onchange="change_brand($(this).get('value'));"}>
				 <span id="account_mode"><{if $account_mode_str}><{$account_mode_str}><{else}><{t}>佣金/底价<{/t}><{/if}></span>
			</div>
			<div class="data-so pro-so">
				 <label><{t}>商品编码：<{/t}></label>
				 <input name="content[bn]" type="text" class="putstyle" size="15" value="<{$content.bn}>">
				 <input type="submit" value="<{t}>搜索<{/t}>" class="btn-search">
			</div>
		</form>
    </div>
    <div class="pro-choose">
        <a href="<{$link.recent_link}>" class="link-grey">Снятые недавно</a>
        <a href="<{$link.marketable_link}>" class="link-orange">В продаже</a>
        <a href="<{$link.dismarketable_link}>" class="link-green">Не в продаже</a>
    </div>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="pro-table">
  <tr>
    <td width="27%"><{t}>商品编码<{/t}></td>
    <td width="47%" align="right"><{t}>状态<{/t}></td>
    <td width="26%"><{t}>操作<{/t}></td>
  </tr>

  <{foreach from=$goods item=item}>
　	<tbody style="border-top:1px solid #ccc; ">
		<{include file='wap/member/manager_goods_items.html'}>
	</tbody>
  <{/foreach}>

</table>
</div>
<{wap_pagers data=$pager}>

<script>
function savegoods(e)
{
	var goods_id = $(e.target).parents('tbody').find('input[name=goods_id]').val();
	var s_price = $(e.target).parents('tbody').find('input[name=s_price]').val();
	var ladder_price = $('input[name="ladder_price"]').val();
	var reg = /^\d+(\.\d+)?$/;
	var re = new RegExp(reg);
	if(s_price != ''){
		if(!re.test(s_price)) {
			alert('<{t}>请输入正确的价格<{/t}>');
			return false;
		}
	}
	if(ladder_price != ''){
		if(!re.test(ladder_price)) {
			alert('<{t}>请输入正确的价格<{/t}>');
			return false;
		}
	}
	var status = 'true';
	var postdata = 'goods_id='+goods_id + '&s_price='+s_price + '&ladder_price='+ladder_price + '&status='+status;
	$.post('<{link app=b2c ctl=wap_member act=update_goods}>', postdata, function(re) {
		try{
			rs = $.parseJSON(re);
		} catch (e) {}
		if(rs.error) {
			if(typeof rs.error === 'string') alert(rs.error);
		}
		if(typeof rs.success === 'string') alert(rs.success);
	});
}

function upgoods(e)
{
	var goods_id = $(e.target).parents('tbody').find('input[name=goods_id]').val();
	var status = 'true';
	var postdata = 'goods_id='+goods_id+'&status='+status;
	$.post('<{link app=b2c ctl=wap_member act=marketable_goods}>', postdata, function(re) {
		var rs;
		try{
			rs = JSON.parse(re);
		} catch (ex) {}
		if(rs.error) {
			if(typeof rs.error === 'string') alert(rs.error);
			return;
		}

		if(rs && rs.content) 
		{
			if($(e.target).parents('tbody')[0])
			{
				$(e.target).parents('tbody')[0].innerHTML = rs.content;
				//商品更新
				if($('.btn-ope3'))
				{
					$('.btn-ope3').on('tap',function(e){
						savegoods(e);
					});
				}

				//上架
				if($('.btn-ope4'))
				{
					$('.btn-ope4').on('tap',function(e){
						upgoods(e);
					});
				}

				//下架
				if($('.btn-ope'))
				{
					$('.btn-ope').on('tap',function(e){
						downgoods(e);
					});
				}
			}
		}
	});
}

function downgoods(e)
{
	var goods_id = $(e.target).parents('tbody').find('input[name=goods_id]').val();
	var status = 'false';
	var postdata = 'goods_id='+goods_id + '&status='+status;
	$.post('<{link app=b2c ctl=wap_member act=marketable_goods}>', postdata, function(re) {
		var rs;
		try{
			rs = JSON.parse(re);
		} catch (ex) {}
		if(rs && rs.error) {
			if(typeof rs.error === 'string') alert(rs.error);
			return;
		}
		if(rs && rs.content) 
		{
			if($(e.target).parents('tbody')[0])
			{
				$(e.target).parents('tbody')[0].innerHTML = rs.content;
				//商品更新
				if($('.btn-ope3'))
				{
					$('.btn-ope3').on('tap',function(e){
						savegoods(e);
					});
				}

				//上架
				if($('.btn-ope4'))
				{
					$('.btn-ope4').on('tap',function(e){
						upgoods(e);
					});
				}

				//下架
				if($('.btn-ope'))
				{
					$('.btn-ope').on('tap',function(e){
						downgoods(e);
					});
				}
			}
		}
	});
}

function change_brand()
{
	var sel_brand = $('#sel_brand').val();
	if(sel_brand)
	{
		$.post('<{link app=b2c ctl=wap_member act=change_brand}>', 'brand_id='+sel_brand, function(re) {
			$('#account_mode').html(re);
		});
	}
	else
	{
		$('#account_mode').html('');
	}
}
(function(){
	//商品更新
	$('.btn-ope3').on('tap',function(e){
		savegoods(e);
	});

	//上架
	$('.btn-ope4').on('tap',function(e){
		upgoods(e);
	});

	//下架
	$('.btn-ope').on('tap',function(e){
		downgoods(e);
	});
})();
</script>